package acs.offer.server;

import acs.http.HttpServerHandler;
import acs.offer.util.OfferDecoder;
import acs.offer.util.OfferEncoder;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.http.HttpObjectAggregator;
import io.netty.handler.codec.http.HttpRequestDecoder;
import io.netty.handler.codec.http.HttpResponseDecoder;
import io.netty.handler.stream.ChunkedWriteHandler;

public class ServerInitializer extends ChannelInitializer<SocketChannel> {
    @Override
    protected void initChannel(SocketChannel ch) throws Exception {
        ChannelPipeline pipeline = ch.pipeline();
//        pipeline.addLast(new OfferEncoder());
//        pipeline.addLast(new OfferDecoder());

        // and then business logic.
//        pipeline.addLast(new ServerHandler());
        pipeline.addLast(new HttpRequestDecoder());
        pipeline.addLast(new HttpObjectAggregator(1024));
        pipeline.addLast(new ChunkedWriteHandler());
        pipeline.addLast(new HttpResponseDecoder());
        pipeline.addLast(new HttpServerHandler());
    }
}
